//
//  RepeadViewController.m
//  Clock
//
//  Created by 郭明皓 on 16/6/23.
//  Copyright © 2016年 郭明皓. All rights reserved.
//

#import "RepeadViewController.h"

@interface RepeadViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong)UITableView *RepeadTableview;
@property (nonatomic, strong)NSArray *RepeadArr;
@property (nonatomic, assign)int RepeatCount;
@end

@implementation RepeadViewController
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
        self.RepeadArr = @[@"每周日", @"每周一", @"每周二", @"每周三", @"每周四", @"每周五", @"每周六"];
        _RepeatCount = 0;
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    self.RepeadTableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height) style:UITableViewStyleGrouped];
    [self.view addSubview:_RepeadTableview];
    self.RepeadTableview.delegate = self;
    self.RepeadTableview.dataSource = self;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.RepeadArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *addtableview = @"tableviewId";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:addtableview];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:addtableview];
    }

    cell.textLabel.text = self.RepeadArr[indexPath.row];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"点击");

    [tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:NO];
    UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
    
    if (cell.accessoryType==UITableViewCellAccessoryNone)
    {
        cell.accessoryType=UITableViewCellAccessoryCheckmark;
        _RepeatCount++;
        NSLog(@"repeatcount = %d",_RepeatCount);
        
    }
    else if (cell.accessoryType==UITableViewCellAccessoryCheckmark)
    {
        cell.accessoryType=UITableViewCellAccessoryNone;
        _RepeatCount--;
        NSLog(@"repeatcount = %d",_RepeatCount);
        
    }

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
